package cn.itsource.utils;

import cn.itsource.dto.AuthUserDto;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @Author: Jason
 * @Date: 2022/9/14 14:04
 */
public class AuthTools {

    //获取当前登录人的个人信息
    public static AuthUserDto getCurrentLoginUserInfo(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        String userInfoJson = (String)authentication.getPrincipal();
        AuthUserDto dto = JSONObject.parseObject(userInfoJson, AuthUserDto.class);
        return dto;
    }
}
